import { defineStore } from "pinia"
import http from "@/utils/request"
import { CategoryItem, ApiRes } from "@/types/data"
import { topCategory } from "../constants"
// 顶级分类默认项
const defaultCategory = topCategory.map(item => {
  return {
    name: item,
  }
})
console.log(defaultCategory);

export default defineStore("category", {
  state: () => ({
    // 分类列表
    list: defaultCategory as CategoryItem[],
  }),
  actions: {
    // 获取分类列表
    async getCategoryList() {
      const res = await http.get<ApiRes<CategoryItem[]>>("/home/category/head")
      // console.log(res)
      this.list = res.data.result
    },
  },
  getters: {},
})
